package com.cachopoid.utils;

import java.util.ArrayList;
import java.util.Iterator;

import com.cachopoid.R;
import com.cachopoid.vo.FotoVO;

import UtilsImagen.ImageLoader;
import android.widget.BaseAdapter;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Gallery;

public class ImageAdapter extends BaseAdapter {

	int mGalleryItemBackground;
	private Context mContext;   
    ArrayList<FotoVO>listaNombreFotos = new ArrayList<FotoVO>();
    
    //TODO cargar las imagenes
   /* private Integer[] mImageIds = {
    		R.drawable.imagen_aniadir,
    		R.drawable.casapedro,
    		R.drawable.lamanduca,
    		R.drawable.mesonviana
    };*/
    
    public ImageAdapter(Context c, ArrayList<FotoVO> listaFotos) {
        mContext = c;
        this.listaNombreFotos = listaFotos;
//        TypedArray attr = mContext.obtainStyledAttributes(R.styleable.gallery);
//        mGalleryItemBackground = attr.getResourceId(
//                R.styleable.gallery_android_galleryItemBackground, 0);
//        attr.recycle();
    
//        for (Iterator iterator = listaFotos.iterator(); iterator.hasNext();) {
//        	
//			FotoVO fotoVO = (FotoVO) iterator.next();
//			listaNombreFotos.add(fotoVO.getFoto());
//			
//		}
       // listaNombreFotos=listaFotos;
    }

    public int getCount() {
        //return mImageIds.length;
    	return listaNombreFotos.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        ImageLoader imageLoader = new ImageLoader(parent.getContext());
        ImageView imageView = new ImageView(mContext);
        Constantes cons = new Constantes();
       //setImageResource(Utils.getDrawable(parent.getContext(),listaNombreFotos.get(position)));
         //holder.imageRanking.setImageDrawable(Utils.getImagenRanking(parent.getContext(),position));
        	imageView.setImageBitmap(imageLoader.getBitmap("http://cachopoid.esy.es/imagenes/cachopos/cachopoLaChalana3.jpg"));
        	imageView.setImageDrawable(imageView.getDrawable());
       // imageView.setImageResource(mImageIds[position]);
        imageView.setLayoutParams(new Gallery.LayoutParams(110, 100));
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        imageView.setBackgroundResource(mGalleryItemBackground);

        return imageView;
    }

}
